//
// Created by yyancy on 2019/11/10.
//

#include <stdio.h>
#include <stdlib.h>
#include <time.h>


char *factor[10] = {"rock", "scissors", "paper"};


int rules[3][3] = {
        {0,  1,  -1},
        {-1, 0,  1},
        {1,  -1, 0}
};

int computer_play() {
    return (rand() % (3 - 1)) + 1 + 1;
}

/**
 * 石头剪刀布游戏
 * @return
 */
int main() {


    srand((unsigned) time(NULL));
    int computer, gamer, result;

    for (int i = 0; i < 10; ++i) {
        printf("Rock Paper Scissors: 1.Rock. 2.Scissors 3.paper: \n");
        scanf("%d%*c", &gamer);
        computer = computer_play();
        printf("computer play %s\n", factor[computer - 1]);
        result = rules[gamer - 1][computer - 1];
        switch (result) {
            case -1:
                printf("computer win!\n");
                break;
            case 0:
                printf("the game ties\n");
                break;
            case 1:
                printf("you win!\n");
                break;
        }

    }
}

